package net.googlecode.exigenlab.Task3.salary;

import net.googlecode.exigenlab.Task3.workers.Manager;
import net.googlecode.exigenlab.Task3.workers.Boss;
import net.googlecode.exigenlab.Task3.workers.Employee;
import net.googlecode.exigenlab.Task3.workers.Person;


/**
 * Calculator of workers salary
 *
 * @author Vitalii Myshenko <a href="mailto:vitalii.myshenko@gmail.com">
 *
 * @since 29.03.11
 */
public class SalaryCalculator {
    private double employeeTax;//value of employee's tax
    private double managerTax;//value of manager's tax
    private double bossTax;//value of boss tax
    private static final double workTime = 170;//monthly working time

    /**
     * Default constructor. Set default taxes
     */
    public SalaryCalculator() {
        this.setEmployeeTax(125);
        this.setManagerTax(250);
        this.setBossTax(350);
    }

    /**
     * Set custom boss tax
     *
     * @param bossTax value of boss tax
     */
    public void setBossTax(double bossTax) {
        bossTax = bossTax;
    }

    /**
     * Get boss tax
     *
     * @return value of boss tax
     */
    public double getBossTax() {
        return bossTax;
    }

    /**
     * Set custom employee tax
     *
     * @param employeeTax value of employee tax
     */
    public void setEmployeeTax(double employeeTax) {
        employeeTax = employeeTax;
    }

    /**
     * Get employee tax
     *
     * @return value of employee tax
     */
    public double getEmployeeTax() {
        return employeeTax;
    }

    /**
     * Set custom manager tax
     *
     * @param managerTax value of manager tax
     */
    public void setManagerTax(double managerTax) {
        managerTax = managerTax;
    }

    /**
     * Get manager tax
     *
     * @return value of manager tax
     */
    public double getManagerTax() {
        return managerTax;
    }

    /**
     * Calculate manager's salary
     *
     * @param person instance of employee class
     */
    public void getSalary(Manager person) {
        double salary = 0;
        if (person.isPerHour()) {
            salary = workTime * person.getRate();
        } else {
            salary = person.getRate();
        }
        if (person.isBonus()) {
            salary += person.getBonusAmount();
        }
        salary -= this.managerTax;
        printSalary(person, salary);
    }

    /**
     * Calculate employee's salary
     *
     * @param person instance of employee class
     */
    public void getSalary(Employee person) {
        double salary = 0;
        if (person.isPerHour()) {
            salary = workTime * person.getRate();
        } else {
            salary = person.getRate();
        }
        if (person.isBonus()) {
            salary += person.getBonusAmount();
        }
        salary -= this.employeeTax;
        printSalary(person, salary);
    }

    /**
     * Calculate boss's salary
     *
     * @param person instance of bass class
     */
    public void getSalary(Boss person) {
        double salary = 0;
        salary = workTime * person.getRate() + person.getBonusAmount() - this.bossTax;
        printSalary(person, salary);
    }

    /**
     * Output data
     *
     * @param person instance of person class
     * @param salary value of workers salary
     */
    private void printSalary(Person person, double salary) {
        System.out.println(person.getPosition() + " >> " + person.getName()
                + " age: " + person.getAge() + " Salary: " + salary);
    }

}

